package com.ruoyi.common.core.web.domain;

import com.ruoyi.common.core.constant.HttpStatus;

import java.util.Map;

/**
 * 操作结果返回对象
 * @param <T> 返回参数实体对象
 * @author 张岩
 * @date 2023/11/21
 */
@SuppressWarnings("unused")
public class ResultObj<T> {

    /** 状态码 */
    private int code;
    /** 计数 */
    private long total;
    /** 消息 */
    private String message;
    /** 级别 */
    private String level;
    /** 返回数据 */
    private T data;
    /** 额外的数据 */
    private Map<Object, Object> extData;
    /** 系统其它代码-预留 */
    private String extCode;

    public ResultObj(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResultObj(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 设置成功提示，默认赋予成功的code
     *
     * @param message 提示消息
     * @return 返回对象
     * @param <T> 泛型类型
     */
    public static <T> ResultObj<T> successMessage(String message) {
        return new ResultObj<>(HttpStatus.SUCCESS, message);
    }

    /**
     * 设置成功提示，默认赋予成功的code
     *
     * @param message 提示消息
     * @param data 返回值附带数据类型
     * @return 返回对象
     * @param <T> 泛型类型
     */
    public static <T> ResultObj<T> successMessage(String message, T data) {
        return new ResultObj<>(HttpStatus.SUCCESS, message, data);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Map<Object, Object> getExtData() {
        return extData;
    }

    public void setExtData(Map<Object, Object> extData) {
        this.extData = extData;
    }

    public String getExtCode() {
        return extCode;
    }

    public void setExtCode(String extCode) {
        this.extCode = extCode;
    }
}
